﻿using UnityEngine;
using System.Collections;

public class CameraSetting : MonoBehaviour {
	public GUISkin myskin;
	public GameObject camera0;
	public GameObject camera1;
	public GameObject camera2;
	public static int camMode = 0;
	private Rect mainRect;
	private Rect miniRect;
	public static int preCamMode = 0;
	public static bool hasChange = false;
	// Use this for initialization
	void Awake () {
		mainRect = new Rect(0,0,Screen.width,Screen.height);
		miniRect = new Rect(3*Screen.width/4,0,Screen.width/4,Screen.height/4);
		if(camMode == 0)
		{
			camera2.SetActive(false);
			camera0.SetActive(true);
			camera1.SetActive(true);
			camera1.tag = "Untagged";
			camera2.tag = "Untagged";
			camera0.tag = "MainCamera";
			camera0.transform.camera.depth = 0;
			camera1.transform.camera.depth = 1;
			camera0.camera.pixelRect = mainRect;
			camera1.camera.pixelRect = miniRect;
		}
	}
	void FixedUpdate(){
		if(camMode == 0)
		{
			preCamMode = 0;
			camera2.SetActive(false);
			camera0.SetActive(true);
			camera1.tag = "Untagged";
			camera2.tag = "Untagged";
			camera0.tag = "MainCamera";
			camera0.transform.camera.depth = 0;
			camera0.camera.pixelRect = mainRect;
			camera0.gameObject.GetComponent<MouseLook>().enabled = true;
			camera0.transform.parent.gameObject.GetComponent<MouseLook>().enabled = true;
			camera0.transform.parent.gameObject.GetComponent<FPSInputController>().enabled = true;

			camera1.transform.camera.depth = 1;
			camera1.camera.pixelRect = miniRect;
			camera1.gameObject.GetComponent<CamDOF>().enabled = false;
		}
		else if(camMode == 1)
		{
			camera0.tag = "Untagged";
			camera2.tag = "Untagged";
			camera1.tag = "MainCamera";

			camera0.gameObject.GetComponent<MouseLook>().enabled = false;
			camera0.transform.parent.gameObject.GetComponent<MouseLook>().enabled = false;
			camera0.transform.parent.gameObject.GetComponent<FPSInputController>().enabled = false;

			camera1.transform.camera.depth = 0;
			camera1.camera.pixelRect = mainRect;
			camera1.gameObject.GetComponent<CamDOF>().enabled = true;

			camera2.gameObject.GetComponent<EditorCamera>().enabled = false;
			camera0.SetActive(false);
			camera2.SetActive(false);
		}
		else if(camMode == 2)
		{
			camera1.tag = "Untagged";
			camera0.tag = "Untagged";
			camera2.tag = "MainCamera";
			preCamMode = 2;
			camera0.SetActive(false);
			camera0.gameObject.GetComponent<MouseLook>().enabled = false;
			camera0.transform.parent.gameObject.GetComponent<MouseLook>().enabled = false;
			camera0.transform.parent.gameObject.GetComponent<FPSInputController>().enabled = false;

			camera2.SetActive(true);
			camera2.transform.camera.depth = 0;
			camera2.camera.pixelRect = mainRect;
			camera2.gameObject.GetComponent<EditorCamera>().enabled = true;

			camera1.transform.camera.depth = 1;
			camera1.camera.pixelRect = miniRect;
			camera1.gameObject.GetComponent<CamDOF>().enabled = false;
		}
	}
	void OnGUI(){
		GUI.skin = myskin;
		if(camMode == 0)
		{
			GUI.Label(new Rect(0,0,Screen.width,22),"","MenuTop1");
			GUI.Button(new Rect(0,0,80,22),"WalkCam","ButtonNone");
			if(GUI.Button(new Rect(80,0,80,22),"EditorCam","SetButtonSmooth"))
			{
				camMode = 2;
				hasChange = true;

			}
			if(GUI.Button(new Rect(160,0,80,22),"DirectCam","SetButtonSmooth"))
			{
				camMode = 1;
			}
		}
		if(camMode == 1)
		{
			GUI.Label(new Rect(0,0,Screen.width,22),"","MenuTop1");
			GUI.Button(new Rect(160,0,80,22),"DirectCam","ButtonNone");
			if(GUI.Button(new Rect(0,0,80,22),"WalkCam","SetButtonSmooth"))
			{
				camMode = 0;
			}
			if(GUI.Button(new Rect(80,0,80,22),"EditorCam","SetButtonSmooth"))
			{
				camMode = 2;
			}
		}
		if(camMode == 2)
		{
			GUI.Button(new Rect(80,22,80,22),"EditorCam","ButtonNone");
			if(GUI.Button(new Rect(0,22,80,22),"WalkCam","SetButtonSmooth"))
			{
				camMode = 0;
				hasChange = true;
			}
			if(GUI.Button(new Rect(160,22,80,22),"DirectCam","SetButtonSmooth"))
			{
				camMode = 1;
			}
			//keyAnimRect = GUI.Window(0,keyAnimRect,KeyAnimationGUI,"","VimtrekWin");
		}
	}
}
